from bipy.components import Component
import pyglet.image


class AnimationConfigurationNotFoundError(Exception):
    pass

class AnimationManager(object):
    def __init__(self):
        super(AnimationManager, self).__init__('animationmanager', 100)
        self.__animations = {}
        self.__grids = {}
        
        
    def __get_grid(self, name):
        if name in self.__grids:
            return self.__grids[ name ]
        else:
            full_path = '.'.join( [__name__, name, name + '.png'] )
            dotcount = 
    
    def __create(self, name):
        parser = ConfigParser()
        ok = parser.read(name)
        if not ok:
            msg = 'could not find animation, %s' % name
            raise AnimationConfigurationNotFoundError(msg)
            
        direction = parser.get('Animation', 'direction')
        topleftx = parser.getint('Animation', 'topleftx')
        toplefty = parser.getint('Animation', 'toplefty')
        width = parser.getint('Animation', 'width')
        height = parser.getint('Animation', 'height')
        
        delay = parser.getfloat('Animation', 'delay')
        anchorx = parser.getint('Animation', 'anchorx')
        anchory = parser.getint('Animation', 'anchory')
        scale_str = parser.get('Animation', 'scale').split(',')
        scale = float(scale_str[0]), float(scale_str[1]), float(scale_str[2])
        rotation = parser.getfloat('Animation', 'rotation') 

        grid = pyglet.image.ImageGrid
        
        
        for frame_nb in range( len(parser.sections()) - 1):
            # set defaults
            frame = AnimationFrame(anchx, anchy, scale, rot, delay, topleftx, toplefty, width, height)
            section = 'Frame%d' % frame_nb
            